package com.java.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.java.dao.PermissionMapper;
import com.java.model.Permission;
import com.java.model.Result;
import com.java.service.PermissionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.sql.Date;
import java.util.List;

@Service
public class PermissionServiceImpl implements PermissionService {

    @Autowired
    private PermissionMapper permissionMapper;

    @Override
    public Result toList(Permission permission) {
        PageHelper.startPage(permission.getPageNum(), permission.getPageSize()); // 提醒page在显示哪一页的数据和要显示多少条数据
        List<Permission> list = permissionMapper.toList(permission);
        PageInfo<Permission> pageInfo = new PageInfo<>(list);
        return Result.success(pageInfo.getList(), pageInfo.getTotal());
    }

    @Override
    public Result get(int id) {
        Permission permission = permissionMapper.get(id);
        return Result.success(permission, null);
    }

    @Override
    public Result save(Permission permission) {
        permissionMapper.save(permission);
        return Result.success();
    }

    @Override
    public Result modify(Permission permission) {
//        permission.setUpdateTime();
        permissionMapper.modify(permission);
        return Result.success();
    }

    @Override
    public Result remove(int[] ids) {
        for (int id : ids) {
            permissionMapper.remove(id);
        }
        return Result.success();
    }

    @Override
    public List<Permission> listByLoginId(int login) {
        return permissionMapper.listByLoginId(login);
    }
}
